package com.ruoyi.wechat.api;

/**
 * 小程序API：营地活动
 */

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.wechat.domain.Activity;
import com.ruoyi.wechat.service.IActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wechat/activity")
public class WxActivityController extends BaseController{
    @Autowired
    private IActivityService activityService;
    /**添加活动 */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Activity activity){
        if(activity == null){
            return  error("数据不能为空");
        }
        if(activity.getCampId() == null){
            return error("营地Id不能为空");
        }
        if (activity.getActivityName() == null){
            return error("活动名称不能为空");
        }
        if(activity.getOriginalPrice() == null){
            return error("原价不能为空");
        }
        return toAjax(activityService.insertActivity(activity));
    }

    /**
     * 根据营地id获取该营地下的活动列表
     * @param campId
     * @return
     */
    @GetMapping("/getInfoByCampId/{campId}")
    public AjaxResult getInfoByCampId(@PathVariable("campId") String campId){
        if(campId == null){
            return error("营地Id不能为空");
        }
        Activity activity = new Activity();
        activity.setCampId(campId);
        List<Activity> list =activityService.selectActivityList(activity);
        return success(list);
    }

    /**
     * 根据活动id查询详情信息
     * @param activityId
     * @return
     */
    @GetMapping("/getInfoByActivityId/{activityId}")
    public AjaxResult getInfoByScenicId(@PathVariable("activityId") String activityId){
        if(activityId ==null){
            return error("活动Id不能为空");
        }
        Activity activity = activityService.selectActivityByActivityId(activityId);
        return success(activity);
    }

    /**
     * 根据活动id完成删除
     * @param activityId
     * @return
     */
    @DeleteMapping("/delete/{activityId}")
    public AjaxResult delete(@PathVariable("activityId") String activityId){
        if(activityId == null){
            return error("活动Id不能为空");
        }
        return toAjax(activityService.deleteActivityByActivityId(activityId));
    }
}

